package  
{
	import flash.events.TextEvent;
	import org.flixel.FlxButton;
	import org.flixel.FlxG;
	import org.flixel.FlxObject;
	import org.flixel.FlxPoint;
	import org.flixel.FlxSprite;
	import org.flixel.FlxText;
	/**
	 * ...
	 * @author João Brant
	 */
	public class Pause extends FlxObject
	{
		private var pausedText:FlxText;
		private var pausedPos:FlxPoint = new FlxPoint(320, 200);
		private var pausedFloat:int=0;
		
		private var telaPreta:FlxSprite;
		
		private var resumeButton:FlxButton;
		private var resumeButtonPos:FlxPoint = new FlxPoint(150, 400);
		private var quitToShopButton:FlxButton;
		private var quitToShopButtonPos:FlxPoint = new FlxPoint(510, 400);
		private var mainMenuButton:FlxButton;
		private var mainMenuButtonPos:FlxPoint = new FlxPoint(510, 400);
		
		private var state:MainState;
		
		public function Pause(mainState:MainState) 
		{
			state = mainState;
			
			telaPreta = new FlxSprite(0, 0, null);
			telaPreta.makeGraphic(Main.windowWidth, Main.windowHeight, 0xaa000000);
			pausedText = new FlxText(0, 0, 300, "Paused");
			pausedText.setFormat(null, 40);
			
			resumeButton = new FlxButton(0, 0, "Resume Game", resumeGame);
			resumeButton.changeButtonSize(2, 2.5);
			
			if (PlayerData.shopUnlocked)
			{
				quitToShopButton = new FlxButton(0, 0, "Quit to Shop", shop);
			}
			else
			{
				quitToShopButton = new FlxButton(0, 0, "Quit to Shop\n(Locked)", shop);
			}
			
			quitToShopButton.changeButtonSize(2, 2.5);
			mainMenuButton = new FlxButton(0, 0, "Main Menu", main);
			mainMenuButton.changeButtonSize(2, 2.3);
		}
		
		override public function preUpdate():void
		{
			super.preUpdate();
			
			telaPreta.preUpdate();
			resumeButton.preUpdate();
			quitToShopButton.preUpdate();
			//mainMenuButton.preUpdate();
		}
		
		override public function update():void
		{
			x = FlxG.camera.scroll.x;
			y = FlxG.camera.scroll.y;
			
			telaPreta.x = x;
			telaPreta.y = y;
			
			pausedText.x = x + pausedPos.x;
			pausedText.y = y + pausedPos.y + 4 * Math.sin((pausedFloat++)/3);
			
			resumeButton.x = x + resumeButtonPos.x;
			resumeButton.y = y + resumeButtonPos.y;
			
			quitToShopButton.x = x + quitToShopButtonPos.x;
			quitToShopButton.y = y + quitToShopButtonPos.y;
			
			mainMenuButton.x = x + mainMenuButtonPos.x;
			mainMenuButton.y = y + mainMenuButtonPos.y;
			
			telaPreta.update();
			resumeButton.update();
			quitToShopButton.update();
			//mainMenuButton.update();
					
			super.update();
		}
		
		override public function postUpdate():void
		{
			super.postUpdate();
			
			telaPreta.postUpdate();
			resumeButton.postUpdate();
			quitToShopButton.postUpdate();
			//mainMenuButton.postUpdate();
		}
		
		override public function draw():void
		{
			telaPreta.draw();
			pausedText.draw();
			resumeButton.draw();
			quitToShopButton.draw();
			//mainMenuButton.draw();
		}
		
		public function resumeGame():void
		{
			state.unpause();
		}
		
		public function main():void
		{
			state.unpause();
			FlxG.switchState(new MenuState);
		}
		
		public function shop():void
		{
			if (!PlayerData.shopUnlocked) return;
			
			state.unpause();
			FlxG.switchState(new ShopState);
		}
		
	}

}